package com.gsdkjgpt4.sys.controller;

import com.gsdkjgpt4.common.vo.Result;
import com.gsdkjgpt4.sys.entity.AuthRequest;
import com.gsdkjgpt4.sys.entity.Identify;
import com.gsdkjgpt4.sys.entity.User;
import com.gsdkjgpt4.sys.service.IHistoryService;
import com.gsdkjgpt4.sys.service.IIdentifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Id;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author rendong
 * @since 2024-01-18
 */
@RestController
@RequestMapping("/identify")
@CrossOrigin
public class IdentifyController {
    @Autowired
    private IIdentifyService identifyService;

    //管理员认证
    @PostMapping("/selectByCode")
    public Result<?> authenticat(@RequestBody Identify identify){
        Map<String,Object> data = identifyService.selectByCode(identify.getCode());

        if(data == null){
            return Result.fail(0,"fail");
        }else if(data.get("codeInfo") == null){
            return Result.fail(-1,"认证码无效！");
        }
        return Result.success(data,"认证码有效！修改认证信息中...");
    }

    @GetMapping("/all")
    public Result<?> getAlluser(){
        List<Identify> list = identifyService.list();
        return Result.success(list,"查询成功");
    }

    @PostMapping("/generateCode")
    public Result<?> generateCode(@RequestBody Identify identify){
        Map<String,Object> data = identifyService.generateCode(identify.getCode(),identify.getPkId());
        if (data == null) {
            return Result.fail("修改错误！");
        }
        return Result.success("修改成功");
    }
}
